﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace MU2DLIB.Input
{
    public sealed class KeyboardManager
    {
        #region Declaration

        private const int INPUTDELAY = 50;

        private KeyboardState m_KeyboardState;

        private static KeyboardManager m_Instance = null;

        #endregion

        #region Constructor

        public KeyboardManager()
        {
        }

        #endregion

        #region Properties

        public int Delay
        {
            get { return INPUTDELAY; }
        }

        #endregion

        #region Methods

        public static KeyboardManager GetInstance()
        {
            if (m_Instance == null)
                m_Instance = new KeyboardManager();

            return m_Instance;
        }

        public Keys[] GetPressedKeys()
        {
            return this.m_KeyboardState.GetPressedKeys();
        }

        public bool IsKeyDown(Keys key)
        {
            if (this.m_KeyboardState.IsKeyDown(key))
                return true;

            return false;
        }

        public bool IsKeyUp(Keys key) 
        {
            if(this.m_KeyboardState.IsKeyUp(key))
                return true;

            return false;
        }

        public void Update(GameTime gameTime)
        {
            this.m_KeyboardState = Keyboard.GetState();
        }

        #endregion
    }
}
